<?php 
 /**
    * FILE:          cieEdit.php
    * LOCATION:      /web_root/views/
    * REFERENCES:    cieList.php
    * FUNCTION:      
    * DEPENDENCIES:  db_connect.php
    * ==============================================================================
    * @version $Id: cieEdit.php,v 0.1 2008/08/10
    * @copyright Copyright (c) none
    * @author ChrisV
    * ==============================================================================
    */
		
	//connect to database
   include('includes/db_connect.php');
		//get requested consumer and form needed    
   $id   = (int)sanitize($_GET['id']);
   $form = (string)sanitize($_GET['form']);
	 //consumer id is 0, new consumer file being made
   if(strcmp($id, '0')==0) {
    $noRecord = true;
	   $btnName  = 'Create Record';
      $title = '<h2 style="	background-image:url(\'./images/pencil.png\');
																				background-repeat:no-repeat;
																				line-height:3em;
																				padding-left:70px;">
																				<span style="font-size:1.3em; font-weight:bold;"> 
																				Create New Case File:</span>
												</h2><p style="font-size:1.1em;font-weight:bold;">** First and Last Name Fields are REQUIRED.</p>';
   }else{
	   //existing record is requested and found
    $noRecord = false;
	   $btnName  = 'Update Record';
		 $query    = "SELECT c.* 	
                  FROM consumer c 
                  WHERE c.id=".mysql_real_escape_string($id);              
		 //echo $query."<br/>";
	   $result   = mysql_query($query);
	   if($row=mysql_fetch_array($result)) {
   	   $lName     =mysql_real_escape_string($row["last_name"]);
					$fName     =mysql_real_escape_string($row["first_name"]);
					$phone     =mysql_real_escape_string($row["phone"]);
					$address   =mysql_real_escape_string($row["address"]);
					$city      =mysql_real_escape_string($row["city"]);
					$state     =mysql_real_escape_string($row["state_id"]);
					$zip       =mysql_real_escape_string($row["zip"]);
					//woodie additions
					//THESE NEEED TO BE ADDED TO THE DATABASE
					$mInitial       								=mysql_real_escape_string($row["middle_initial"]);
					$social_security_number  =mysql_real_escape_string($row["ssn"]);
					$medicaid_number       			=mysql_real_escape_string($row["medicaid"]);
					$medicare_number       			=mysql_real_escape_string($row["medicare"]);
					$county       										=mysql_real_escape_string($row["county"]);
	   } 
      //record found is being edited	
      $title = '<h2 style="	background-image:url(\'./images/case_file.png\');
																				background-repeat:no-repeat;
																				line-height:3em;
																				padding-left:70px;">
																				<span style="font-size:1.3em; font-weight:bold;"> Edit Case File:</span>
																				<div class="gt-success" style="display:inline; font-size:1.3em; font-weight:bold;">'
																				.$fName.' '
																				.$lName.'</div>
												</h2>'; 
   }
   if(sanitize($_GET["Status"])) {
?>
      <p style="font-weight:bold; font-size: 1.3em;">
			<?php echo $_GET["Status"]; ?>
		</p>
<?php 
   }
      if(sanitize($_GET["Error"])) {
?>
      <p style="font-weight:bold; font-size: 1.3em;">
			<?php echo $_GET["Error"]; ?>
		</p>
<?php 
   }
?>
<?php 
	//show user case file function and file being used
echo $title; 
?>
		<!-- BEGIN CONSUMER METADATA FORM-->
		<form action="./actions/ProcessConsumerUpdate.php" 
				 id="form" name="form" 
				 onsubmit="return validate(this)" method="post">
				<div style="background:#eee; border:1px #ddd solid;padding:3px;">
					<table class="consumer_tab">
							<tr>
  <?php                     
							if(!$noRecord) {                 
?>
								<td style="width:60px;">
									<div class="formUnitSml" style="width: 160px;">
										<label class="readable">Consumer Id:</label>
											<input class="data" 
																style="width: 50px;"
																type="text" 
																name="consumerId" 
																readonly disabled value="<?php echo $id ?>"/>
									</div>
								</td>
 <?php                   
							} 
?>			
								<td style="width:300px;">
									<div class="formUnitSml">
										<label class="readable">First Name:</label>
											<input class="data" style="width:130px;" type="text" 
															name="fName" id="fName" value="<?php echo $fName ?>"/>
															<?php if(isset($fNameError))echo'<br /><span style="color:#0000FF;font-weight:bold;">'.$fNameError.'</span>'; ?>
									</div>
								</td>
								<td>
									<div class="formUnitSml">
										<label class="readable">Last Name:</label>
											<input class="data" style="width:130px;" type="text" 
															name="lName" id="lName" value="<?php echo $lName ?>"/>
															<?php if(isset($lNameError)) echo '<br /><span style="color:#0000FF;font-weight:bold;">'.$lNameError.'</span>'; ?>
									</div>
								</td>
								<td id="middleinitial">
										<div class="formUnitSml">
											<label class="readable">Middle Initial:</label>
											<input class="data" style="width:25px;"type="text" 
											name="mInitial" id="mInitial" value="<?php echo $mInitial ?>"/>
											<?php if(isset($mNameError)) echo '<br /><span style="color:#0000FF;font-weight:bold;">'.$mNameError.'</span>'; ?>
										</div>
								</td>
							</tr>
							<tr>
									<td style="width:350px;">    
											<div class="formUnitSml">
													<label class="readable"><span class="privateinfo">Social Security #:</span></label>
													<input class="data" type="text" 
																	name="social_security_number" 
																	id="social_security_number" 
																value="<?php echo $social_security_number ?>" style="width:100px"/>
											</div>
									</td>
									<td style="width:300px;">    
										<div class="formUnitSml">
											<label class="readable"><span class="privateinfo">Medicaid #:</span></label>
											<input class="data" type="text" 
																name="medicaid_number"
																id="medicaid_number"
																value="<?php echo $medicaid_number ?>" style="width:100px"/>
										</div>
									</td>
									<td style="width:300px;">    
										<div class="formUnitSml">
											<label class="readable"><span class="privateinfo">Medicare #:</span></label>
											<input class="data" type="text" 
																name="medicare_number" 
																id="medicare_number"
																value="<?php echo $medicare_number ?>" style="width:100px"/>
										</div>
									</td>
									<td>    
										<div class="formUnitSml">
											<label class="readable">Phone:</label>
											<input class="data" type="text" 
															name="phone" id="phone"
															value="<?php echo $phone ?>" style="width:110px"/>
										</div>
									</td>
								</tr>  
								<tr>
									<td colspan="9">
											<p class="gt-error" style="text-align:center;margin-top:1px; margin-bottom:1px;">
												<strong>All consumer information with red background labels is
													* PRIVATE DATA *.  DO NOT disclose this data WITHOUT WRITTEN CONSENT.</strong>
											</p>
									</td>
								</tr>
							</table>
							<table width="100%" style="margin-top:5px;" class="consumer_tab">
								<tr>
									<td colspan="3" style="padding-top:5px;">
											<div class="formUnitSml" style="width:400px">
												<label class="readable">Address:</label>
												<input class="data" style="width: 300px;"type="text" 
																	name="address" id="address" value="<?php echo $address ?>" style="width:350px"/>
											</div>
									</td>
									<td>
											<div class="formUnitSml" style="width:240px">
												<label style="width:50px" class="readable">City:</label>
												<input class="data" type="text" name="city" 
																	id="city"
																	style="width:150px" value="<?php echo $city ?>"/>
											</div>
									</td>
									<td>
											<div class="formUnitSml" style="width:130px">
												<label style="width:40px" class="readable">State:</label>
													<select name="state" id="state" style="width:70px" class="data" >
 <?php 
															$stateQuery = "SELECT * FROM lst_state";
															$result     = mysql_query($stateQuery);         
															while($row=mysql_fetch_array($result)) {    
																	$state_id = $row["id"];
																	$abbr     = $row["abbr"];          
																	if($state==$state_id){           
																			echo "<option value=\"".$state_id."\" selected>".$abbr."</option>";       
																	}else{           
																			echo "<option value=\"".$state_id."\">".$abbr."</option>";             
																	}       
															}         
?>
												</select>
											</div>
										</td>
									</tr>
									<tr>
										<td>          
											<div class="formUnitSml" style="width:250px">
												<label style="width:80px" class="readable">County:</label>
												<input class="data" type="text" name="county" 
																id="county" style="width:160px" value="<?php echo $county ?>"/>
											</div>
										</td>
										<td>          
											<div class="formUnitSml" style="width:150px">
													<label style="width:70px" class="readable">Zip Code:</label>
													<input class="data" type="text" name="zip" 
																		id="zip" style="width:60px" value="<?php echo $zip ?>"/>
											</div>
										</td>
									</tr>
								</table>
							</div>
							<br/>
 <?php 
   /**
         *allow user to update existing consumer meta-data
         *or to cancel and get back to consumer search form.
		*/ 
						if(!$form) {     
?>
							<p style="text-align:right">  
								<input class="btn" 
													style="background-color: #fff;
														background-image:url('./images/gt/btn-blank-long.jpg');
													 background-repeat:no-repeat;
													 border:none;
													 width:160px;
													 height: 30px;
													 color: #fff;
													 font-weight:bold;"
													type="submit" 
													value="<?php echo $btnName; ?>" />
								<input class="btn" 
													style="background-color: #fff;
														background-image:url('./images/gt/btn-blank-long.jpg');
													 background-repeat:no-repeat;
													 border:none;
													 width:160px;
													 height: 30px;
													 color: #fff;
													 font-weight:bold;"
														type="button" value="Cancel" 
														onclick="window.location='admin.php?action=cie';"/>
							</p>
<?php 
						}	 
?>
						<input type="hidden" value="<?php echo $id;?>" name="id" />
		</form>
<!-- container -->
   <!-- END CONSUMER METADATA FORM -->     
	 
   <?php   
	 //CASE FILE CONTROLLER
   /*
				determines which form the user has decided to update existing consumer infor in database, or
				to create inital data entry for new consumer. looks for selection parameter in url. 
		*/
   if(strcmp($form,"intake1")==0) {  
			include('forms/intake1.php');
   } else if(strcmp($form, "intake2")==0) {
      include('forms/intake2.php');
   } else if(strcmp($form, "ilpcsr")==0) {
      include('forms/ilpcsr.php');
   } else if(strcmp($form, "authToRelease")==0) {
      include('forms/authToRelease.php');
   } else if(strcmp($form, "monthlyISRList")==0) {
				include('forms/monthlyISRList.php');
   } else if(strcmp($form, "monthlyISR")==0) {
      include('forms/monthlyISR.php');
   } else if(strcmp($form, "irEntry")==0) {
   	include('forms/irEntry.php');
   } else if(strcmp($form, "enroll")==0) {
   	include('forms/enroll.php');
   } else if(!$noRecord) {     
   /* 
			A RECORD WAS FOUND.........CHOOSE FORM if existing consumer found or new consumer created,
			present the user with a drop down control so a form can be chosen. 
      */      
 ?>
      <div id="formUnit" 
			style="border-top:1px #ccc dotted;padding-top:25px;">
			<div style="margin-left:350px;">
         <label style="padding:15px; text-align:center; font-weight:bold;">
				Grab A Case File Form  To Use:
		</label><br />
         <select name="entryForm" id="entryForm">
				<option value=""></option>
				<option value="intake1"><?php echo THIS_CIL;?> Intake (Page 1)</option>
				<option value="intake2"><?php echo THIS_CIL; ?> Intake (Page 2)</option>
				<option value="authToRelease">Authorization To Release Information</option>
				<option value="ilpcsr"><?php echo THIS_CIL;?> ILP/CSR</option>
				<!-- <option value="enroll">Enroll In Programs</option> -->
				<option value="monthlyISR">Case Notes</option>
				<option value="irEntry">Consumer I&R</option>
         </select>
         <input type="button" 
							style="background-color: #fff;
														background-image:url('./images/gt/btn-blank-long.jpg');
													 background-repeat:no-repeat;
													 border:none;
													 width:160px;
													 height: 30px;
													 color: #fff;
													 font-weight:bold;"
							class="btn" value="Load Form" onclick="chooseForm($('entryForm'));"/>
		</div>
	</div>
      <!-- DATA ENTRY FORM CONTROLLER -->
      <script type="text/javascript">
         function chooseForm(obj) {
            value = obj.options[obj.selectedIndex].value;
            if(value=='intake1') {
               window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=intake1';   
            } else if(value=='intake2') {
               window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=intake2';
            } else if(value=='ilpcsr') {
               window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=ilpcsr';
            } else if(value=='authToRelease') {
	     	    window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=authToRelease';
	   	    }  else if(value=='monthlyISR') {
				window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=monthlyISRList';
	   	     } else if(value=='irEntry') {
				window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=irEntry';
             //}else if(value=='enroll') {
               //window.location='admin.php?action=cieedit&id=<?php echo $id; ?>&form=enroll';
             }
         }
      </script>
<?php 
   } //end !noRecord if
?>